package com.example.idlefish.GoodsInfo.ActivityContract

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.MediaStore
import androidx.activity.result.contract.ActivityResultContract

class PickPhotoActivityContract:ActivityResultContract<Unit, Uri>() {
    override fun createIntent(context: Context, input: Unit): Intent {
        val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
        return intent
    }

    override fun parseResult(resultCode: Int, intent: Intent?): Uri {
        if(resultCode != Activity.RESULT_OK || intent == null)
        {
            return Uri.EMPTY
        }
        val IamgeUri = intent.data ?: throw IllegalArgumentException("Intent data is null")
        return IamgeUri
    }
}